<template>
  <div class="app-container p-rel">
    <div class="container-title">查询</div>
    <form-edit class="p-abs" :detailForm="detailForm" :isEdit="isEdit" @submitForm="submitForm" :editVisible.sync="editVisible" v-if="editVisible"></form-edit>
    <el-form :model="queryParams"  ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="85px">
      <el-row :gutter="15">
        <el-col :lg="8" :xl="6">
        </el-col>
        <el-col :lg="8" :xl="6">
            <el-button type="primary" icon="" size="" @click="handleQuery">搜索</el-button>
            <el-button icon="" size="" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8 tableBtnListCss">
      <el-col :span="1.5">
        <el-button type="primary" @click="addBtn">添加</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" @click="importBtn">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" @click="downloadTemplateBtn">下载导入模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" @click="syncBtn">同步</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="orgList" @selection-change="handleSelectionChange">
      <el-table-column type="index" width="55" align="center" label="序号"/>
      <el-table-column label="医疗机构名称" align="center" prop="enterpriseName" >
        <template #default="scope">
          <el-button type="text" @click="rowDetailBtn(scope.row)">{{ scope.row.enterpriseName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="累计记分" align="center" prop="scoring" />
      <el-table-column label="机构类别" align="center" prop="categoryListName" />
      <el-table-column label="所在区/县" align="center" prop="county" />
      <el-table-column label="镇/街道" align="center" prop="town" />
      <el-table-column label="医疗等级" align="center" prop="medicalLevel" />
      <el-table-column label="备案状态" align="center" prop="recordStatus" />
      <el-table-column label="是否注册平台" align="center" prop="registerStatus" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="380">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="checkSelfBtn(scope.row)">机构自查自纠</el-button>
          <el-button size="mini" type="text" @click="prescriptionAuthBtn(scope.row)">处方权限授权</el-button>
          <el-button size="mini" type="text" @click="lookDetailBtn(scope.row)">查看详情</el-button>
          <el-button size="mini" type="text" @click="lookSortBtn(scope.row)">查看记分情况</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listOrg, getOrg, delOrg, addOrg, updateOrg } from "@/api/zhangping/zpMedicalOrg";
import formEdit from './editFrom.vue'
export default {
  name: "Org",
  components:{ formEdit },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医疗机构信息表格数据
      orgList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        creditCode: null,
        scoring: null,
        medicalLevel: null,
        recordStatus: null,
        recordStart: null,
        recordEnd: null,
        recordCertificates: null,
        physicianNum: null,
        nurseNum: null,
        createId: null,
        updateId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailForm:{},
      isEdit:false,
      editVisible:false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    checkSelfBtn(){
      const obj = {
        path: '/healthCare/zpMedicalOrg/checkSelf',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    prescriptionAuthBtn(){
      const obj = {
        path: '/healthCare/zpMedicalOrg/prescriptionAuth',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    rowDetailBtn(){
      const obj = {
        path: '/healthCare/zpMedicalOrg/rowDetail',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    lookDetailBtn(){
      const obj = {
        path: '/healthCare/zpMedicalOrg/detail',
        query: {
          id: '111',
        }
      }
      this.$router.push(obj);
    },
    lookSortBtn(){
      
    },
    importBtn(){
      
    },
    downloadTemplateBtn(){
      
    },
    syncBtn(){
      
    },
    addBtn(){
      const path = '/healthCare/zpMedicalOrg/detail'
      this.$router.push(path);
    },
    /** 查询医疗机构信息列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then(response => {
        this.orgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        creditCode: null,
        scoring: null,
        medicalLevel: null,
        recordStatus: null,
        recordStart: null,
        recordEnd: null,
        recordCertificates: null,
        physicianNum: null,
        nurseNum: null,
        createId: null,
        createBy: null,
        createTime: null,
        updateId: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.detailForm = {}
      this.isEdit = false
      this.editVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row,type) {
      // this.reset();
      const id = row.id || this.ids
      getOrg(id).then(response => {
        this.detailForm = response.data
        if(type == 1){
          this.isEdit = true
        }else{ // 查看
          this.isEdit = false
        }
        this.editVisible = true

      });
    },
    /** 提交按钮 */
    submitForm(form,id) {
    if (id != null) {
      updateOrg(form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.editVisible = false;
        this.getList();
      });
    } else {
      addOrg(form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.editVisible = false;
        this.getList();
      });
    }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除医疗机构信息编号为"' + ids + '"的数据项？').then(function() {
        return delOrg(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zpMedical/org/export', {
        ...this.queryParams
      }, `org_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.app-container{
  .tableBtnListCss{
    margin-top: 10px;
    border-top: 1px solid #e0e0e0;
    padding-top: 10px;
  }
}
</style>